<template>
  <Dialog title="办理出院" class="single-column" :visible="visible" button-text="办理出院" @close="handleClose(1)" @confirm="handleConfirm">
    <!-- 办理出院 -->
    <div v-loading="loading">
      <el-row type="flex">
        <el-col :span="6" style="width: 100px;text-align: right;">顾客：</el-col>
        <el-col :span="18" style="width: 235px;">{{ selectRow.customerName }}</el-col>
      </el-row>
      <el-row type="flex">
        <el-col :span="6" style="width: 100px;text-align: right;">床位：</el-col>
        <el-col :span="18" style="width: 235px;">{{ selectRow.bed }}</el-col>
      </el-row>
      <el-row type="flex">
        <el-col :span="6" style="width: 100px;text-align: right;">入院时间：</el-col>
        <el-col :span="18" style="width: 235px;">{{ selectRow.admissionTime }}</el-col>
      </el-row>
      <el-row type="flex">
        <el-col :span="6" style="width: 100px;text-align: right;">出院时间：</el-col>
        <el-col :span="18" style="width: 235px;">{{ selectRow.dischargeTime }}</el-col>
      </el-row>
      <el-row type="flex">
        <el-col :span="6" style="width: 100px;text-align: right;">共计：</el-col>
        <!-- <el-col :span="10">{{ selectRow.days }}天</el-col> -->
        <el-col :span="18" style="width: 235px;">{{ selectRow.hospitalizationDay }}天</el-col>
      </el-row>
      <el-row type="flex">
        <el-col :span="6" style="width: 100px;text-align: right;">所属项目：</el-col>
        <el-col :span="18" style="width: 235px;">{{ selectRow.projectName }}</el-col>
      </el-row>
      <el-row type="flex">
        <el-col :span="6" style="width: 100px;text-align: right;">主治医生：</el-col>
        <el-col :span="18" style="width: 235px;">{{ selectRow.attendingDoctorName }}</el-col>
      </el-row>
    </div>
  </Dialog>
</template>

<script>
import Dialog from "@/components/Dialog";
export default {
  components: { Dialog },
  data() {
    return {
      loading: false,
      selectRow: {},
      visible: false,
    };
  },
  methods: {
    handleClose(row) {
      if (row === 1) {
        this.visible = false;
        this.selectRow = {};
      } else {
        this.visible = true;
        this.selectRow = row;
        this.$set(row, 'days', this.DateDiff(row.admissionTime, row.dischargeTime));
      }
    },
    handleConfirm() {
      this.loading = true;
      // console.log(this.selectRow);
      this.$api[`department/inpatient/out`]({ id: this.selectRow.id }).then(res => {
        if (res.code !== 200) return this.$message.error('办理出院失败');
        this.msgSuccess('办理出院成功');
        this.handleClose(1);
        this.$emit("success");
      }).finally(() => (this.loading = false));
    },
    DateDiff(sDate1, sDate2) { // sDate1和sDate2是2002-12-18格式
      var aDate, oDate1, oDate2, iDays;
      aDate = sDate1.split("-");
      oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]); // 转换为12-18-2002格式
      aDate = sDate2.split("-");
      oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);
      // console.log(oDate1, oDate2);
      iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24); // 把相差的毫秒数转换为天数
      return iDays;
    },
  },
};
</script>
<style lang="scss" scoped>
.el-col{
  line-height: 40px;
}
</style>
